package com.example.statistics.ex

import android.widget.TextView
import com.jhj.httplibrary.HttpCall
import java.math.BigDecimal

fun String?.empty(): String {
    return if (this.isNullOrEmpty() || this == "/") "" else this
}

val String?.formatPath: String
    get() {
        if (this != null) {
            return if (isUrl()) {
                this.replace("\\", "/")
            } else {
                HttpCall.baseUrl + "/upload" + this
            }
        }
        return ""
    }

/**
 * 数值格式化，去除小数点多余的0
 */
val String?.numberFormat: String
    get() {
        val default = "0"
        if (this.isNumber()) {
            val value = this.orEmpty().toBigDecimal()
            val noZero = value.stripTrailingZeros()
            if (noZero == BigDecimal(0)) return default
            return noZero.toPlainString()
        } else {
            return default
        }

    }

